<%-- 
    Document   : list
    Created on : 2012-9-6, 14:38:04
    Author     : Danny Lee
--%>
<%
    pageContext.setAttribute("contextPath", request.getContextPath());
//    pageContext.setAttribute("loginUser", session.getAttribute(AuthenticationFilter.AUTH_INFO));
%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">        
        <title>JSP Page</title>

        <link rel="stylesheet" href="${contextPath}/resources/css/easyui/easyui.css"/>
        <link rel="stylesheet" href="${contextPath}/resources/css/style.css"/>
        <link rel="stylesheet" href="${contextPath}/resources/css/icon.css"/>      
        <script type="text/javascript" src="${contextPath}/resources/js/jquery.js"></script>
        <script type="text/javascript" src="${contextPath}/resources/js/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="${contextPath}/resources/js/easyui-lang-zh_CN.js"></script>
        <script type="text/javascript" src="${contextPath}/resources/js/mask.js"></script>
        <script type="text/javascript" src="${contextPath}/resources/js/js.js"></script>
        <script type="text/javascript">
            $(function(){
                $cList = $('#configList');
                $cList.datagrid({
                    title:'配置列表', //标题  
                    method:'post',  
                    iconCls:'icon-tedit', //图标  
                    singleSelect:true, //多选  
                    height:360, //高度  
                    width:550, //宽度  
                    striped: true, //奇偶行颜色不同  
                    collapsible:true,//可折叠  
                    url:"${contextPath}/config/list/data", //数据来源  
                    //                      sortName: 'userNo', //排序的列  
                    //                      sortOrder: 'desc', //倒序  
                    remoteSort: true, //服务器端排序  
                    idField:'id', //主键字段  
                    queryParams:{}, //查询条件  
                    pagination:true, //显示分页  
                    rownumbers:true, //显示行号
                    loadMsg:"正在加载，请稍候...",//远程加载时的提示信息
                    columns:[[
                            {field:'remark',title:'配置名称',width:360,sortable:true},
                            {field:'value',title:'配置值',width:140,sortable:true,editor:'text'}
                        ]],
                    onClickCell: function(rowIndex, field, value){
                        if($cList.data('editing') && $cList.data('editRow')!=null && $cList.data('editRow') != rowIndex){
                            $cList.datagrid('endEdit',$cList.data('editRow'));
                            $cList.data('editing',false);
                            return false;
                        }
                        //                        $list.datagrid('selectRow',rowIndex);
                        //                        var selected = $list.datagrid('getSelected');
                        if(field == 'value'){
                            $cList.datagrid('beginEdit',rowIndex);
                            $cList.data('editing',true);
                            $cList.data('editRow',rowIndex);
                        }else{
                            if($cList.data('editing')){
                                $cList.datagrid('endEdit',$cList.data('editRow'));
                                $cList.data('editing',false);
                            }
                        }
                        $(".datagrid-editable-input:first").select();
                    },
                    onAfterEdit : function(rowIndex, rowData, changes){
                        if($.isEmptyObject(changes)){
                            return false;
                        }
                        var url = '${contextPath}/config/update';
                        $.ajax({
                            url : url,
                            data : {
                                value : parseFloat(rowData.value),
                                name : rowData.name
                            },
                            cache : false,
                            dataType : "json",
                            type : "POST",
                            success : function(rs) {
                                if(rs.result){
                                    $.messager.show({
                                        title:'友情提示',
                                        msg:rowData.remark+'的系统配置修改成功'
                                    });
                                    $cList.datagrid('load');
                                }
                            }
                        });
                    }
                });
                var p = $cList.datagrid('getPager');
                $(p).pagination({
                    pageSize: 10,//每页显示的记录条数，默认为10 
                    pageList: [5,10,20,30,40,50],//可以设置每页记录条数的列表 
                    beforePageText: '第',//页数文本框前显示的汉字 
                    afterPageText: '页    共 {pages} 页', 
                    displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
                });
                $('body').click(function(e){
                    if($cList.data('editRow')!=null){
                        if(!$(e.target).is('.datagrid-body table *')){
                            $cList.datagrid('endEdit',$cList.data('editRow'));
                            $cList.data('editing',false);
                        }
                    }
                });
            });          
        </script>
    </head>

    <body>
        <script type="text/javascript">
            $("body").mask({
                maskMsg:"正在初始化，请稍后...",
                timeout:1000,
                opacity:1
            });
        </script>
        <table id="configList"></table>
    </body>
</html>
